package com.flejay.dao.example;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.flejay.core.generic.dao.CrudServiceDaoImpl;
import com.flejay.model.example.Employee;

@Repository("employeeDAO")
public class EmployeeDAOImpl extends CrudServiceDaoImpl<Employee> implements IEmployeeDAO {

	@Override
	public void persistEmployee(Employee employee) {
		this.persist(employee);
	}

	@Override
	public Employee findEmployeeById(long id) {
		return this.findById(Employee.class, id);
	}

	@Override
	public void updateEmployee(Employee employee) {
		this.update(employee);

	}
	@Override
	public void deleteEmployee(Employee employee) {
		this.delete(employee);
	}

	@Override
	public List<Employee> findByAge(long age) {
		String queryString = "SELECT e FROM Employee e WHERE e.age=:age";
		Query query = this.getCurrentSession().createQuery(queryString);
		query.setParameter("age", age);
		List<Employee> res = (List<Employee>)query.list();
		return res;
	}

}